package com.ag.dgm.action;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.stereotype.Controller;

import com.ag.bean.TbUser;
import com.ag.common.BaseAction;
import com.ag.common.IPermissionService;
import com.ag.dgm.service.IMessageToSendService;

@Controller("messageSendAction")
public class MessageSendAction extends BaseAction implements SessionAware {

	private static final long serialVersionUID = 8318262948960693552L;

	@Resource(name = "messageToSendServiceImpl")
	private IMessageToSendService service;

	// 用来得到用户
	@Resource(name = "PermissionServiceImpl")
	private IPermissionService pms;

	private Map<String, Object> sessionMap;

	private String ids; // 收短信人id
	private String names; // 收短信人名称
	private String callees; // 收短信人电话
	private String msg; // 短信内容
	private String senderName; // 发信人名称
	private String result;

	public IMessageToSendService getService() {
		return service;
	}

	public IPermissionService getPms() {
		return pms;
	}

	public void setPms(IPermissionService pms) {
		this.pms = pms;
	}

	public Map<String, Object> getSessionMap() {
		return sessionMap;
	}

	public void setSessionMap(Map<String, Object> sessionMap) {
		this.sessionMap = sessionMap;
	}

	public void setService(IMessageToSendService service) {
		this.service = service;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

	public String getNames() {
		return names;
	}

	public void setNames(String names) {
		this.names = names;
	}

	public String getCallees() {
		return callees;
	}

	public void setCallees(String callees) {
		this.callees = callees;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getSenderName() {
		return senderName;
	}

	public void setSenderName(String senderName) {
		this.senderName = senderName;
	}

	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}



	/**
	 * 得到用户信息
	 */

	public TbUser findUser() {
		System.out.println("这是findUser_eventReportAction方法");
		TbUser tbUser = (TbUser) pms.getCurrentUser(sessionMap);
		return tbUser;
	}
	@Override
	public void setSession(Map<String, Object> session) {
		this.sessionMap = session;
		
	}
	

	public String sendMessage() {
		System.out.println("这是sendMessage_action方法");
		senderName = findUser().getUName();
		result = "发送短信成功";
		try {
			service.sendMessage(senderName, ids, names, callees, msg);
		} catch (Exception e) {
			result = "发送短信失败";
			e.printStackTrace();
		}
		return "sendMessage";
	}



}
